package cfs.formbean;

import java.util.ArrayList;
import java.util.List;

import org.mybeans.form.FormBean;

public class CreateEmployeeFormBean extends FormBean {

	private String username;
	private String password;
	private String confirmpassword;
	private String firstname;
	private String lastname;

	public String getUsername() {
		return username;
	}

	public String getPassword() {
		return password;
	}

	public String getConfirmpassword() {
		return confirmpassword;
	}

	public String getFirstname() {
		return firstname;
	}

	public String getLastname() {
		return lastname;
	}

	public void setUsername(String s) {
		username = s.trim();
	}

	public void setPassword(String s) {
		password = s.trim();
	}

	public void setConfirmpassword(String s) {
		confirmpassword = s.trim();
	}

	public void setFirstname(String s) {
		firstname = trimAndConvert(s, "<>\"");
		;
	}

	public void setLastname(String s) {
		lastname = trimAndConvert(s, "<>\"");
	}

	public List<String> getValidationErrors() {
		List<String> errors = new ArrayList<String>();

		if (firstname == null || firstname.length() == 0) {
			errors.add("First name is required");
		}

		if (lastname == null || lastname.length() == 0) {
			errors.add("Last name is required");
		}

		if (username == null || username.length() == 0) {
			errors.add("User Name is required");
		}

		if (password == null || password.length() == 0) {
			errors.add("Password is required");
		}

		if (confirmpassword == null || confirmpassword.length() == 0) {
			errors.add("Confirm Password is required");
		}

		if (errors.size() > 0) {
			return errors;
		}

		if (!username.matches("[\\w]+")) {
			errors.add("user name can only contain word characters");
			username = trimAndConvert(username, "<>\"");
		}

		if (password.matches(".*[<>\"].*")) {
			errors.add("password  may not contain angle brackets or quotes");
		}

		if (confirmpassword.matches(".*[<>\"].*")) {
			errors.add("confirm password  may not contain angle brackets or quotes");
		}

		if (errors.size() > 0) {
			return errors;
		}

		if (username.length() < 6) {
			errors.add("User Name should not less than 6");
		}

		if (password.length() < 6) {
			errors.add("Password must be more than 6 Letters");
		}

		if (!password.equals(confirmpassword)) {
			errors.add("password are not same");
		}

		return errors;

	}

}
